package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.IndexNoticeVo;
import com.ruoyi.system.vo.IndexVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 首页Controller
 *
 * @author ruoyi
 * @date 2024-01-05
 */
@RestController
@RequestMapping("/index")
public class IndexController extends BaseController
{
    @Autowired
    private IEvectionService evectionService;
    @Autowired
    private IAskLeaveService askLeaveService;
    @Autowired
    private ILeaveService leaveService;
    @Autowired
    private IEmplyeeService emplyeeService;
    @Autowired
    private INoticeService noticeService;
    @Autowired
    private IRepairService repairService;
    /**
     * 待办列表
     */
    @GetMapping(value = "/wait/{index}")
    public AjaxResult list(@PathVariable("index") Long index)
    {
        //返回的vo
        IndexVo indexVo = new IndexVo();
        List<Evection> evections = evectionService.selectListByStatus(index);
        List<AskLeave> askLeaveList = askLeaveService.selectListByStatus(index);
        List<Leave> leaveList = leaveService.selectListByStatus(index);
        List<Repair> repairList = repairService.selectListByStatus(index);
        indexVo.setAskLeave(askLeaveList);
        indexVo.setEvection(evections);
        indexVo.setLeaves(leaveList);
        indexVo.setRepairList(repairList);
        return success(indexVo);
    }

    /**
     * 通知公告列表
     */
    @GetMapping(value = "/getNoticeList/{index}")
    public AjaxResult getNoticeList(@PathVariable("index") Long index)
    {
        //返回的vo
        IndexNoticeVo indexVo = new IndexNoticeVo();
        List<Notice> notices = noticeService.selectListByStatus(index);
        indexVo.setNotices(notices);
        return success(indexVo);
    }

    /**
     * 获取用户数量
     */
    @GetMapping(value = "/getUserNum")
    public AjaxResult getUserNum()
    {
        int userNum = emplyeeService.getUserNum();
        return success(userNum);
    }

    /**
     * 获取登录用户名
     */
    @GetMapping(value = "/getUserName")
    public AjaxResult getUserName()
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
        Emplyee emplyee = emplyeeService.selectEmplyeeByEno(sysUser.getEno());
        System.out.println("当前登录用户名: "+emplyee.getName());
        return success(emplyee.getName());
    }
}
